package com.qinker.oa.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qinker.oa.dao.WorkInfoDao;
import com.qinker.oa.exception.GlobalException;
import com.qinker.oa.message.CodeMsg;
import com.qinker.oa.model.WorkInfo;
import com.qinker.oa.params.UserResult;
import com.qinker.oa.service.WorkInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class WorkInfoServiceImpl implements WorkInfoService {

    @Autowired
    private WorkInfoDao workInfoDao;

    @Override
    public PageInfo<UserResult> getUserListGroupByWork(int page, int pageSize) {
        PageHelper.startPage(page, pageSize);
        List<UserResult> userResults = workInfoDao.getUserListGroupByWork();
        PageInfo<UserResult> info = new PageInfo<>(userResults);
        return info;
    }

    @Override
    public List<WorkInfo> getWorkInfoList(int uId) {
        return workInfoDao.getWorkInfoList(uId);
    }

    @Override
    @Transactional
    public void addWorkInfo(WorkInfo workInfo) {
        try{
            workInfoDao.addWorkInfo(workInfo);
        }catch (Exception e){
            throw new GlobalException(CodeMsg.SERVER_ERROR);
        }
    }
}
